//
//  GTBuyGiftController.m
//  GiftTalk
//
//  Created by Wan on 16/3/29.
//  Copyright © 2016年 Wan. All rights reserved.
//

#import "GTBuyGiftController.h"
#import <View+MASShorthandAdditions.h>
#import <NJKWebViewProgress.h>
#import <NJKWebViewProgressView.h>

@interface GTBuyGiftController () <UIWebViewDelegate>

/** webView */
@property (weak, nonatomic) UIWebView *webView;
/** 页面加载进度条 */
@property (strong, nonatomic) NJKWebViewProgress *progress;

@end

@implementation GTBuyGiftController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self setupWebView];
    
    [self setupWebProgressView];
}

- (void)setupWebView {
    // 页面加载
    UIWebView *webView = [[UIWebView alloc] init];
    [self.view addSubview:webView];
    NSURL *buyUrl = [NSURL URLWithString:self.url];
    NSURLRequest *request = [NSURLRequest requestWithURL:buyUrl];
    [webView loadRequest:request];
    self.webView.delegate = self;
    
    // 设置位置
    [webView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view).insets(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
    self.webView = webView;
}

#pragma mark - WebView ProgressView
- (void)setupWebProgressView {
    NJKWebViewProgressView *webProgressView = [[NJKWebViewProgressView alloc] init];
    [self.view addSubview:webProgressView];
    [webProgressView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.topLayoutGuide);
        make.left.right.equalTo(self.view);
        make.height.equalTo(@5);
    }];
    
    self.progress = [[NJKWebViewProgress alloc] init];
    self.webView.delegate = self.progress;
    __weak typeof(webProgressView) weakWebProgressView = webProgressView;

    self.progress.progressBlock = ^(float progress) {
        weakWebProgressView.progress = progress;
    };
    self.progress.webViewProxyDelegate = self;
    
    
}

#pragma mark - <UIWebViewDelegate>
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    GTLogFunc
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
